//
//  SSRetweetStatusCell.swift
//  MyMicroBlog
//
//  Created by stevenSu on 15/8/3.
//  Copyright © 2015年 stevenSu. All rights reserved.
//

import UIKit
private let pictureButtonBackgroundColor = UIColor(white: 0.9, alpha: 1.0)
class SSRetweetStatusCell: SSStatusCell {
    
    func pictureButtonClicked(btn: UIButton) {
        print(btn)
    }
    
    private lazy var pictureButton: UIButton = {
        let button = UIButton()
        button.backgroundColor = pictureButtonBackgroundColor
        button.addTarget(self, action: "pictureButtonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()
    
    private lazy var pictureLabel: FFLabel = {
        let lbl = FFLabel(fontColor: UIColor.darkGrayColor(), fontSize: 14)
        lbl.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 2 * contentOffSet
        lbl.labelDelegate = self
        return lbl
    }()
    
    override var status: SSStatus? {
        didSet {
            // TODO: color not set
            let name = status?.retweeted_status?.user?.name ?? ""
            let text = status?.retweeted_status?.text ?? ""
            pictureLabel.text = "@\(name):\(text)"
        }
    }
    
    override func setupUI() {
        super.setupUI()
        contentView.insertSubview(pictureButton, belowSubview: pictureView)
        contentView.addSubview(pictureLabel)
        
        pictureButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -contentOffSet, y: contentOffSet))
        pictureButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: footerView, size: nil)
        
        pictureLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: pictureButton, size: nil, offset: CGPoint(x: contentOffSet, y: contentOffSet))
        
        let constraint = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: pictureLabel, size: CGSize(width: 280, height: 280), offset: CGPoint(x: 0, y: contentOffSet))
        pictureViewConstraintsW = pictureView.ff_Constraint(constraint, attribute: NSLayoutAttribute.Width)
        pictureViewConstraintsH = pictureView.ff_Constraint(constraint, attribute: NSLayoutAttribute.Height)
    }

}
